package com.jzr.task.controller.api;

import com.jzr.task.job.shiyan.*;
import com.jzr.task.db2.mapper.ShiyanMapper;
import com.jzr.task.db2.model.ShiyanBed;
import com.jzr.task.db2.model.ShiyanPatient;
import com.jzr.task.util.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/api/shiyan")
public class ShiyanController {

    @Autowired
    private ShiyanMapper shiyanMapper;

    @GetMapping("/getBedList")
    public List<ShiyanBed> getBedList(){
        return  shiyanMapper.getBedList();
    }

    @GetMapping("/getPatientList")
    public List<ShiyanPatient> getPatientList(){
        return shiyanMapper.getPatientList();
    }



    @GetMapping("/syncPatient")
    public String syncPatient(){
        try {
            ShiyanSyncPatient syncPatient = (ShiyanSyncPatient) SpringUtil.getBean("Shiyan.SyncPatient");
            syncPatient.process();
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/syncDept")
    public String syncDept(){
        try {
            ShiyanSyncDept syncDept = (ShiyanSyncDept) SpringUtil.getBean("Shiyan.SyncDept");
            syncDept.process();
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/syncDoctor")
    public String syncDoctor(){
        try {
            ShiyanSyncDoctor syncDoctor = (ShiyanSyncDoctor) SpringUtil.getBean("Shiyan.SyncDoctor");
            syncDoctor.process();
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/syncNurse")
    public String syncNurse(){
        try {
            ShiyanSyncNurse syncNurse = (ShiyanSyncNurse) SpringUtil.getBean("Shiyan.SyncNurse");
            syncNurse.process();
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/syncBed")
    public String syncBed(){
        try {
            ShiyanSyncBed syncBed = (ShiyanSyncBed) SpringUtil.getBean("Shiyan.SyncBed");
            syncBed.process();
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
        return "success";
    }


}
